import numpy as np
from sklearn.linear_model import Ridge
from Liner_Regress.simple import SimpleRegress


# 岭回归模型（继承一元线性回归模型）
class RidgeRegress(SimpleRegress):
    def __init__(self,remain_dec=2,_lambda=1.0):
        SimpleRegress.__init__(self,remain_dec)
        # 正则化参数
        self._lambda = _lambda
    def fit(self,train_x: list[float],train_y: list[float])->None:
        x,y = np.array(train_x),np.array(train_y)
        self.temp_data = y
        ridge_model = Ridge(alpha=self._lambda)
        ridge_model.fit(x,y)
        self.slope = ridge_model.coef_[0]
        self.intercept = ridge_model.intercept_
